package com.ares.basic.exception;

import lombok.Data;

/**
 * 自定义异常
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2016年10月27日 下午10:11:27
 */
@Data
public class BusinessException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private String msg;

    private String code;

    private Object result;

    public BusinessException(String message) {
        this("500", message);
    }

    public BusinessException(String xCode, String message) {
        this(xCode, message, new Throwable());
    }

    public BusinessException(String xCode, String message, Object result) {
        this(xCode, message, result, new Throwable());
    }

    public BusinessException(String xCode, String message, Object result, Throwable throwable) {
        this(xCode, message, result, throwable.getMessage(), throwable);
    }

    public BusinessException(String code, String message, Throwable throwable) {
        this(code, message, throwable.getMessage(), throwable);
    }

    public BusinessException(String xCode, String message, String internalMessage, Throwable throwable) {
        this(xCode, message, null, internalMessage, throwable);
    }

    public BusinessException(String xCode, String message, Object result, String internalMessage, Throwable throwable) {
        super("[" + xCode + "] - " + message + internalMessage, throwable);
        this.msg = message;
        this.code = xCode;
        this.result = result;
    }
}
